using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class ProductListModel : ModelBase
    {
        public ProductListModel()
        {
            client.DeleteProductCompleted += DoDeleteProductCompleted;
            client.GetProductCollectionCompleted += DoGetProductCollectionCompleted;
            client.GetSingleProductCompleted += DoGetSingleProductCompleted;
            client.SearchProductCompleted += DoSearchProductCompleted;
            client.UpdateProductCompleted += DoUpdateProductCompleted;
            client.InsertProductCompleted += DoInsertProductCompleted;
            client.UndoDeleteProductCompleted += DoUndoDeleteProductCompleted;
            client.GetWarehouseCollectionCompleted += DoGetWarehouseCollectionCompleted;
            client.GetPartnerCollectionByParamCompleted += DoGetPartnerCollectionCompleted;
            client.GetProductCollectionTypeCompleted += DoGetProductCollectionTypeCompleted;
        }

        #region GetPartnerCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Partner>> GetCustomerCollectionCompleted;

        public int GetCustomerCollectionAsync()
        {
            client.GetPartnerCollectionByParamAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetPartnerCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Partner> e)
        {
            if (GetCustomerCollectionCompleted != null)
            {
                GetCustomerCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetWarehouseCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Warehouse>> GetWarehouseCollectionCompleted;

        public int GetWarehouseCollectionAsync()
        {
            client.GetWarehouseCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetWarehouseCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Warehouse> e)
        {
            if (GetWarehouseCollectionCompleted != null)
            {
                GetWarehouseCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region InsertProduct

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertProductCompleted;

        public int InsertProductAsync(Product data)
        {
            client.InsertProductAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoInsertProductCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (InsertProductCompleted != null)
            {
                InsertProductCompleted(sender, e);
            }
        }

        #endregion

        #region UpdateProduct

        public event EventHandler<FeedbackCompletedEventArgs> UpdateProductCompleted;

        public int UpdateProductAsync(Product data)
        {
            client.UpdateProductAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUpdateProductCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UpdateProductCompleted != null)
            {
                UpdateProductCompleted(sender, e);
            }
        }

        #endregion

        #region SearchProduct

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Product>> SearhProductCompleted;

        public int SearchProductAsync(ProductCriteria criteria)
        {
            client.SearchProductAsync(criteria);
            return WebConstants.MagicNumer;
        }

        void DoSearchProductCompleted(object sender, CollectionFeedbackCompletedEventArgs<Product> e)
        {
            if (SearhProductCompleted != null)
            {
                SearhProductCompleted(sender, e);
            }
        }

        #endregion

        #region GetProductCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Product>> GetProductCollectionCompleted;

        public int GetProductCollectionAsync(bool isShowAll)
        {
            client.GetProductCollectionAsync(isShowAll);
            return WebConstants.MagicNumer;
        }

        void DoGetProductCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Product> e)
        {
            if (GetProductCollectionCompleted != null)
            {
                GetProductCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetProductCollectionType

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Product>> GetProductCollectionTypeCompleted;

        public int GetProductCollectionTypeAsync(bool isShowAll)
        {
            client.GetProductCollectionTypeAsync(isShowAll);
            return WebConstants.MagicNumer;
        }

        void DoGetProductCollectionTypeCompleted(object sender, CollectionFeedbackCompletedEventArgs<Product> e)
        {
            if (GetProductCollectionTypeCompleted != null)
            {
                GetProductCollectionTypeCompleted(sender, e);
            }
        }

        #endregion

        #region DeleteProduct

        public event EventHandler<FeedbackCompletedEventArgs> DeleteProductCompleted;

        public int DeleteProductAsync(int data)
        {
            client.DeleteProductAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoDeleteProductCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (DeleteProductCompleted != null)
            {
                DeleteProductCompleted(sender, e);
            }
        }

        #endregion

        #region UndoDeleteProduct

        public event EventHandler<FeedbackCompletedEventArgs> UndoDeleteProductCompleted;

        public int UndoDeleteProductAsync(int data)
        {
            client.UndoDeleteProductAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUndoDeleteProductCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UndoDeleteProductCompleted != null)
            {
                UndoDeleteProductCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleProduct

        public event EventHandler<SingleFeedbackCompletedEventArgs<Product>> GetSingleProductCompleted;

        public int GetSingleProductAsync(int objID)
        {
            client.GetSingleProductAsync(objID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleProductCompleted(object sender, SingleFeedbackCompletedEventArgs<Product> e)
        {
            if (GetSingleProductCompleted != null)
            {
                GetSingleProductCompleted(sender, e);
            }
        }

        #endregion
    }
}